{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $operation == 'display'} class="active" {/if}><a href="{php echo $this->createWebUrl('huodong',array('op' =>'display'))}">活动</a></li>
	<li{if empty($huodong['id']) && $operation == 'post'} class="active" {/if}><a href="{php echo $this->createWebUrl('huodong',array('op' =>'post'))}">添加活动</a></li>
	{if !empty($huodong['id']) &&  $operation == 'post'}<li  class="active"><a href="{php echo $this->createWebUrl('huodong',array('op' =>'post','id'=>$huodong['id']))}">编辑活动</a></li>{/if}
	{if $operation == 'canyu'}<li class="active"><a href="###">参与列表</a></li>{/if}
	{if $operation == 'canyuedit'}<li class="active"><a href="###">代理商活动编辑</a></li>{/if}
	{if $operation == 'teamjiang'}<li class="active"><a href="###">配置团队奖</a></li>{/if}
	{if $operation == 'xiajia'}<li class="active"><a href="###">下架商品</a></li>{/if}
</ul>

{if $operation == 'display'}
<div class="main panel panel-default">
	<div class="panel-body table-responsive">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th>标题</th>
					<th>时间</th>
					<th style="text-align:right;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $huodong}
				<tr>
					<td>
						<span class="label label-success">{$huodong['title']}</span>
					</td>
					<td>
						<div>{php echo date("Y-m-d H:i:s",$huodong['starttime'])}</div>
						<div style="margin-top:5px;">{php echo date("Y-m-d H:i:s",$huodong['endtime'])}</div>
					</td>
					<td style="text-align:right;">
						<div>
						{if $huodong['endtime'] > TIMESTAMP && $huodong['tqjs'] == 0}
						<a href="{php echo $this->createWebUrl('huodong', array('op' => 'tingzhi', 'id' => $huodong['id']))}" onclick="return confirm('提前结束活动将无法继续开启，确认吗？');return false;" class="btn btn-danger btn-sm">提前结束</a>
						{/if}
						{if $_W["account"]["type_name"] == "公众号"}
						<a href="{php echo $this->createWebUrl('huodong', array('op' => 'tongzhi', 'id' => $huodong['id']))}" onclick="return confirm('群发模板消息有风险，确认操作吗？');return false;" class="btn btn-warning btn-sm">通知代理商</a>
						{/if}
						{if $huodong['endtime'] > TIMESTAMP}
						<a href="{php echo $this->createWebUrl('huodong', array('op' => 'teamjiang', 'id' => $huodong['id']))}" class="btn btn-info btn-sm">配置团队奖</a>
						{/if}
						<a href="{php echo $this->createWebUrl('order', array('hdid' => $huodong['id']))}" class="btn btn-success btn-sm">查看订单</a>
						</div>
						<div style="margin-top:5px;">
							<a href="{php echo $this->createWebUrl('huodong', array('op' => 'post', 'id' => $huodong['id']))}" class="btn btn-default btn-sm" title="修改"><i class="fa fa-edit"></i></a>
							<a href="{php echo $this->createWebUrl('huodong', array('op' => 'canyu', 'id' => $huodong['id']))}" class="btn btn-default btn-sm">{$huodong['canyunum']}个参与</a>
							<a href="{php echo $this->createWebUrl('huodong', array('op' => 'peihuo', 'id' => $huodong['id']))}" onclick="return confirm('确认要导出配货单吗？');return false;" class="btn btn-default btn-sm">导出配货单</a>
							<a href="{php echo $this->createWebUrl('huodong', array('op' => 'xiajia', 'id' => $huodong['id']))}" class="btn btn-default btn-sm">下架商品</a>
							<a href="{php echo $this->createWebUrl('huodong', array('op' => 'delete', 'id' => $huodong['id']))}" onclick="return confirm('此操作不可恢复，确认吗？');return false;" class="btn btn-default btn-sm" title="删除"><i class="fa fa-times"></i></a>
						</div>
					</td>
				</tr>
				{/loop}
			</tbody>
		</table>
	</div>
</div>
{$pager}

{elseif $operation == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
		<input type="hidden" name="id" value="{$huodong['id']}" />
		<div class="panel panel-default">
			<div class="panel-heading">活动设置</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">标题</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="title" class="form-control" value="{$huodong['title']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">下单必填自定义字段</label>
					<div class="col-sm-9 col-xs-12">
						<label class="radio-inline"><input type="radio" name="autofield" value="0" {if $huodong['autofield'] == 0}checked="true"{/if} /> 关闭</label>
						&nbsp;&nbsp;&nbsp;
						<label class="radio-inline"><input type="radio" name="autofield" value="1" {if $huodong['autofield'] == 1}checked="true"{/if} /> 身份证</label>
						&nbsp;&nbsp;&nbsp;
						<label class="radio-inline"><input type="radio" name="autofield" value="2" {if $huodong['autofield'] == 2}checked="true"{/if} /> 微信号</label>							
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享标题</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="sharetitle" class="form-control" value="{$huodong['sharetitle']}"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享图标</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_image('sharethumb', $huodong['sharethumb'], '', array('extras' => array('text' => 'readonly')))}
						<span class="help-block" style="color:red;">推荐尺寸200*200</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享描述</label>
					<div class="col-sm-7 col-xs-12">
						<textarea class="form-control" name="sharedes">{$huodong['sharedes']}</textarea>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">开始时间</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_date('starttime',date('Y-m-d H:i:s',$huodong['starttime']),true);}
					</div>
				</div>		
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">结束时间</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_date('endtime',date('Y-m-d H:i:s',$huodong['endtime']),true);}
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">活动商品</label>
					<div class="col-sm-9 col-xs-12">
						{loop $goodslist $goods}
						<label for="goods{$goods['id']}" class="checkbox-inline"><input name="goodsid[]" value="{$goods['id']}" id="goods{$goods['id']}" {if $goods['has']}checked="checked"{/if} type="checkbox"> {$goods['title']}</label>
						&nbsp;&nbsp;&nbsp;
						{/loop}
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">代理商自主定价</label>
					<div class="col-sm-9 col-xs-12">
						<label for="candj1" class="radio-inline"><input name="candj" value="1" id="candj1" {if $huodong['candj'] == 1}checked="true"{/if} type="radio"> 支持</label>
						&nbsp;&nbsp;&nbsp;
						<label for="candj2" class="radio-inline"><input name="candj" value="0" id="candj2" {if $huodong['candj'] == 0}checked="true"{/if} type="radio"> 不支持</label>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">配送方式</label>
					<div class="col-sm-9 col-xs-12">
						<label for="pstype1" class="radio-inline"><input name="pstype" value="0" id="pstype1" {if $huodong['pstype'] == 0}checked="true"{/if} type="radio"> 平台配送</label>
						&nbsp;&nbsp;&nbsp;
						<label for="pstype2" class="radio-inline"><input name="pstype" value="1" id="pstype2" {if $huodong['pstype'] == 1}checked="true"{/if} type="radio"> 代理商配送</label>
					</div>
				</div>
				
				<div id="sss" {if $huodong['pstype'] == 1}style="display:none;"{/if}>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">免运费</label>
					<div class="col-sm-9 col-xs-12">
						<div class="input-group">
							<span class="input-group-addon">满</span>
							<input class="form-control" name="manjian" value="{$huodong['manjian']}" type="text">
							<span class="input-group-addon">元免运费</span>
						</div>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">支持自提</label>
					<div class="col-sm-9 col-xs-12">
						<label for="canziti1" class="radio-inline"><input name="canziti" value="1" id="canziti1" {if $huodong['canziti'] == 1}checked="true"{/if} type="radio"> 是</label>
						&nbsp;&nbsp;&nbsp;
						<label for="canziti2" class="radio-inline"><input name="canziti" value="0" id="canziti2" {if $huodong['canziti'] == 0}checked="true"{/if} type="radio"> 否</label>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">支持送货</label>
					<div class="col-sm-9 col-xs-12">
						<label for="cansonghuo1" class="radio-inline"><input name="cansonghuo" value="1" id="cansonghuo1" {if $huodong['cansonghuo'] == 1}checked="true"{/if} type="radio"> 是</label>
						&nbsp;&nbsp;&nbsp;
						<label for="cansonghuo2" class="radio-inline"><input name="cansonghuo" value="0" id="cansonghuo2" {if $huodong['cansonghuo'] == 0}checked="true"{/if} type="radio"> 否</label>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">支持货到付款（自提当面付款）</label>
					<div class="col-sm-9 col-xs-12">
						<label for="candmfk1" class="radio-inline"><input name="candmfk" value="1" id="candmfk1" {if $huodong['candmfk'] == 1}checked="true"{/if} type="radio"> 是</label>
						&nbsp;&nbsp;&nbsp;
						<label for="candmfk2" class="radio-inline"><input name="candmfk" value="0" id="candmfk2" {if $huodong['candmfk'] == 0}checked="true"{/if} type="radio"> 否</label>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">运费模板</label>
					<div class="col-sm-9 col-xs-12">
						{loop $yunfeilist $yunfei}
						<label for="yunfei{$yunfei['id']}" class="radio-inline"><input name="yfid" value="{$yunfei['id']}" id="yunfei{$yunfei['id']}" {if $huodong['yfid'] == $yunfei['id']}checked="checked"{/if} type="radio"> {$yunfei['title']}</label>
						&nbsp;&nbsp;&nbsp;
						{/loop}
					</div>
				</div>
				</div>
			</div>
		</div>
		<div class="form-group col-sm-12">
			<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
			<input type="hidden" name="token" value="{$_W['token']}" />
		</div>
	</form>
</div>
<script>
$(function(){
	$("input[name='pstype']").click(function(){
		if($(this).val() == 0){
			$("#sss").show();
		}else{
			$("#sss").hide();
		}
	});
})
</script>
{elseif $operation == 'canyu'}
<div class="panel panel-default">
	<div class="panel-body table-responsive">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th style="width:5%;">ID</th>
					<th style="width:20%;">商家名称</th>
					<th style="width:15%;">参与时间</th>
					<th style="text-align:right;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $merchanthdlist $item}
				<tr>
					<td>{$item['id']}</td>
					<td>{$item['merchant']['name']}</td>
					<td>
						<span class="label label-success">{php echo date("Y-m-d H:i:s",$item['time'])}</span>
					</td>
					<td style="text-align:right;">
						<a href="{php echo $this->createWebUrl('order', array('hdid' => $item['hdid'],'merchant_id'=>$item['merchant_id']))}" class="btn btn-info btn-sm">{$item['ordernum']}个订单</a>
						<a href="{php echo $this->createWebUrl('huodong', array('id' => $item['id'], 'op' => 'canyuedit'))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="编辑"><i class="fa fa-pencil"></i></a>
						<a href="{php echo $this->createWebUrl('huodong', array('op' => 'deletecanyu', 'id' => $item['id'], 'hdid' => $item['hdid']))}" onclick="return confirm('此操作不可恢复，确认吗？');return false;" class="btn btn-default btn-sm" title="删除"><i class="fa fa-times"></i></a>
					</td>
				</tr>
				{/loop}
			</tbody>
		</table>
		{$pager}
	</div>
	</div>
</div>
{/if}

{if $operation == 'xiajia'}
<div class="panel panel-default">
	<div class="panel-body table-responsive">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th style="width:5%;">ID</th>
					<th style="width:50%;">商品名称</th>
					<th style="width:10%;">库存</th>
					<th style="text-align:right;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $goodslist $item}
					<tr>
						<td>{$item['goodsres']['id']}</td>
						<td>{$item['goodsres']['title']}</td>
						<td>{$item['goodsres']['total']}</td>
						<td style="text-align:right;">
							<a href="{php echo $this->createWebUrl('huodong', array('op' => 'doxiajia', 'hdid' => $item['hdid'], 'goodsid' => $item['goodsid']))}" onclick="return confirm('此操作不可恢复，确认吗？');return false;" class="btn btn-danger btn-sm">下架</a>
						</td>
					</tr>
				{/loop}
			</tbody>
		</table>
		{$pager}
	</div>
	</div>
</div>
{/if}

{if $operation == 'canyuedit'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
		<input type="hidden" name="id" value="{$merchanthd['id']}" />
		<div class="panel panel-default">
			<div class="panel-heading">代理商活动编辑</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享标题</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="sharetitle" class="form-control" value="{$merchanthd['sharetitle']}" />
					</div>
				</div>

				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享二维码</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_image('sharethumb', $merchanthd['sharethumb'], '', array('extras' => array('text' => 'readonly')))}
						<span class="help-block" style="color:red;">开吧源码社区推荐尺寸200*200</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享描述</label>
					<div class="col-sm-7 col-xs-12">
						<textarea class="form-control" name="sharedes">{$merchanthd['sharedes']}</textarea>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">运费</label>
					<div class="col-sm-9 col-xs-12">
						<div class="input-group">
							<input class="form-control" name="yunfei" value="{$merchanthd['yunfei']}" type="text">
							<span class="input-group-addon">元</span>
						</div>
					</div>
				</div>
			
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">免运费</label>
					<div class="col-sm-9 col-xs-12">
						<div class="input-group">
							<span class="input-group-addon">满</span>
							<input class="form-control" name="manjian" value="{$merchanthd['manjian']}" type="text">
							<span class="input-group-addon">元免运费</span>
						</div>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">支持自提</label>
					<div class="col-sm-9 col-xs-12">
						<label for="canziti1" class="radio-inline"><input name="canziti" value="1" id="canziti1" {if $merchanthd['canziti'] == 1}checked="true"{/if} type="radio"> 是</label>
						&nbsp;&nbsp;&nbsp;
						<label for="canziti2" class="radio-inline"><input name="canziti" value="0" id="canziti2" {if $merchanthd['canziti'] == 0}checked="true"{/if} type="radio"> 否</label>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">支持送货</label>
					<div class="col-sm-9 col-xs-12">
						<label for="cansonghuo1" class="radio-inline"><input name="cansonghuo" value="1" id="cansonghuo1" {if $merchanthd['cansonghuo'] == 1}checked="true"{/if} type="radio"> 是</label>
						&nbsp;&nbsp;&nbsp;
						<label for="cansonghuo2" class="radio-inline"><input name="cansonghuo" value="0" id="cansonghuo2" {if $merchanthd['cansonghuo'] == 0}checked="true"{/if} type="radio"> 否</label>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">支持货到付款（自提当面付款）</label>
					<div class="col-sm-9 col-xs-12">
						<label for="candmfk1" class="radio-inline"><input name="candmfk" value="1" id="candmfk1" {if $merchanthd['candmfk'] == 1}checked="true"{/if} type="radio"> 是</label>
						&nbsp;&nbsp;&nbsp;
						<label for="candmfk2" class="radio-inline"><input name="candmfk" value="0" id="candmfk2" {if $merchanthd['candmfk'] == 0}checked="true"{/if} type="radio"> 否</label>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">展示倒计时</label>
					<div class="col-sm-9 col-xs-12">
						<label for="daojishi1" class="radio-inline"><input name="daojishi" value="1" id="daojishi1" {if $merchanthd['daojishi'] == 1}checked="true"{/if} type="radio"> 是</label>
						&nbsp;&nbsp;&nbsp;
						<label for="daojishi2" class="radio-inline"><input name="daojishi" value="0" id="daojishi2" {if $merchanthd['daojishi'] == 0}checked="true"{/if} type="radio"> 否</label>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">展示购买记录</label>
					<div class="col-sm-9 col-xs-12">
						<label for="buydetail1" class="radio-inline"><input name="buydetail" value="1" id="buydetail1" {if $merchanthd['buydetail'] == 1}checked="true"{/if} type="radio"> 是</label>
						&nbsp;&nbsp;&nbsp;
						<label for="buydetail2" class="radio-inline"><input name="buydetail" value="0" id="buydetail2" {if $merchanthd['buydetail'] == 0}checked="true"{/if} type="radio"> 否</label>
					</div>
				</div>
				
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">选择商品</label>
					<div class="col-sm-9 col-xs-12">
						{loop $goodsarr $goods}
						<label class="checkbox-inline"><input name="goodsid[]" value="{$goods['goods']['id']}-{$goods['optionid']}" {if $goods['has']}checked="checked"{/if} type="checkbox"> {$goods['goods']['title']}{if $goods['optionid'] > 0}<span style="color:red;">[{$goods['optionname']}]</span>{/if}</label>
						&nbsp;&nbsp;&nbsp;
						{/loop}
					</div>
				</div>
			</div>
		</div>
		<div class="form-group col-sm-12">
			<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
			<input type="hidden" name="token" value="{$_W['token']}" />
		</div>
	</form>
</div>
{elseif $operation == 'teamjiang'}
<div class="main">
	<div class="alert alert-danger" role="alert">
		<div>1、团队奖只能在活动结束前配置</div>
		<div>2、团队奖是阶梯制模式，例如100-1000元奖励团队销售额的5%、例如1001-2000元奖励团队销售额的8%。以此类推</div>
		<div>3、团队奖只能在活动结束后在<a href="{php echo $this->createWebUrl('teamjiang',array('hdid'=>$id))}" style="color:green;">团队奖管理</a>里发放</div>
	</div>
	<form action="" method="post" class="form-horizontal form">
		<input type="hidden" name="id" value="{$id}" />
		<div class="panel panel-default">
			<div class="panel-heading">配置团队奖</div>
			<div class="panel-body">
				<table class="table table-hover">
					<thead>
					<tr>
						<th>起始价格</th>
						<th>截止价格</th>
						<th>奖励比例</th>
						<th width="10%">操作</th>
					</tr>
					</thead>
					<tbody id="option-items">
						{loop $teamjiang $p}
						<tr>
							<td>
								<div class="input-group">
									<input name="startmoney[]" type="text" class="form-control" value="{$p['startmoney']}"/>
									<span class="input-group-addon">元</span>
								</div>
							</td>
							<td>
								<div class="input-group">
									<input name="endmoney[]" type="text" class="form-control" value="{$p['endmoney']}"/>
									<span class="input-group-addon">元</span>
								</div>
							</td>
							<td>								
								<div class="input-group">
									<span class="input-group-addon">团队销售额</span>
									<input name="jiangli[]" type="text" class="form-control" value="{$p['jiangli']}"/>
									<span class="input-group-addon">%</span>
								</div>
							</td>
							<td>
								<a href="javascript:;" onclick="deleteoption(this)" style="margin-top:10px;" title="删除"><i class="fa fa-remove"></i></a>
							</td>
						</tr>
						{/loop}
					</tbody>
					<tbody>
						<tr>
							<td colspan="4">
								<a href="javascript:;" id='add-option' onclick="addoption()" style="margin-top:10px;"  title="添加"><i class='fa fa-plus'></i>添加</a>
							</td>
						</tr>
					</tbody>
				</table>

			</div>
		</div>
		<div class="form-group col-sm-12">
			<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
			<input type="hidden" name="token" value="{$_W['token']}" />
		</div>
	</form>
</div>
<script language="javascript">
	function addoption() {
		var html = '<tr>'
						+'<td>'
							+'<div class="input-group">'
								+'<input name="startmoney[]" type="text" class="form-control" />'
								+'<span class="input-group-addon">元</span>'
							+'</div>'
						+'</td>'
						+'<td>'
							+'<div class="input-group">'
								+'<input name="endmoney[]" type="text" class="form-control" />'
								+'<span class="input-group-addon">元</span>'
							+'</div>'
						+'</td>'
						+'<td>'
							+'<div class="input-group">'
								+'<span class="input-group-addon">团队销售额</span>'
								+'<input name="jiangli[]" type="text" class="form-control" />'
								+'<span class="input-group-addon">%</span>'
							+'</div>'
						+'</td>'
						+'<td>'
							+'<a href="javascript:;" onclick="deleteoption(this)" style="margin-top:10px;" title="删除"><i class="fa fa-remove"></i></a>'
						+'</td>'
					+'</tr>';
		$('#option-items').append(html);
	}
	function deleteoption(o) {
		$(o).parent().parent().remove();
	}
</script>
{/if}
{template 'common/footer'}